<template>
    <view class="g_content">
        <view class="dis_f_c_c" v-if="isLoading" style="height: 100vh;">
        <u-loadmore  status="loading" />
        </view>
        <view v-else>
            <u-swiper height="300" imgMode="heightFix" radius="0" :list="swiperList" @click="handleShowImg"></u-swiper>
            <view class="p_20">
                <view class="">
                    <view class="f_s_18">{{infoData.bt}}</view>
                    <view class="dis_f_l_c m_t_5">
                        <view class="m_r_10">
                            <u-tag :text="infoData.lxNameYj" type="success" size="mini"></u-tag>
                        </view>
                        <u-tag :text="infoData.lxNameEj" type="success" size="mini"></u-tag>
                    </view>
                </view>
                <view class="card_box p_10 m_t_10">
                    <view class="dis_f_r_c" v-if="isExaminePeople=='false'">
                        <u-icon name="phone" size="30" @click="handleToTel"></u-icon>
                    </view>
                    <s-header :userInfo="userData" ></s-header>
                    <view v-if="isExaminePeople=='true'" class="dis_f_r_c c_9 f_s_14">联系电话：{{infoData.lxrDh}}</view>
                    <view class="dis_f_r_c c_9 f_s_14 m_t_10">{{infoData.createTime}}</view>
                </view>
                <view class="card_box p_10 m_t_10">
                    <view class="dis_f_r_c c_9 f_s_14 m_t_10">  <u-icon name="map" ></u-icon>{{infoData.province}}{{infoData.city}}{{infoData.districts}}</view>
                    <view >{{infoData.nr}}</view>
                </view>
            </view>
        </view>
        <u-popup :show="showVideo" >
            <view style="height: 100vh;">
                <video v-if="videoUrl" :src="videoUrl" autoplay loop :show-fullscreen-btn="false" :show-play-btn="false" :show-center-play-btn="false" :show-loading="false" style="width: 100%;height: 100%;"></video>
            </view>
        </u-popup>
        <!-- 授权弹窗 -->
        <s-auth-modal />
    </view>
</template>

<script>
import {
    getListInfoApi,
    addCollectApi,
    delCollectApi,
    viewPhoneApi,
    getMyInfoApi,
    getByKeyApi,
    watchAdvertisementsApi
} from "@/sheep/api";

export default {
    name: "info",
    data() {
        return {
            isLoading:false,
            isExaminePeople:false,
            videoUrl:'',
            city:'',
            adTime:'',
            showVideo:false,
            getListInfoApi:{},
            src:'',
            swiperList: [],
            infoData:{},
            userData:{},
            myInfoVo:{},
            queryData:{},
            timer:null,
        }
    },
    onLoad(params) {
        this.isExaminePeople = params.isExaminePeople
        this.city = uni.getStorageSync('city')
        this.goodsId = params.goodsId;
        this.queryData.id = params.goodsId
        this.getInfo()
        this.getMyInfo()
        this.getadTime()
    },
    onShareAppMessage() {
        return {
            title: '['+this.infoData.typeName+']'+this.infoData.bt,
            imageUrl: this.swiperList[0],
            path: '/pages/index/index'
        }
    },
    onUnload(){
        let index = uni.getStorageSync('activeIndex')
        const app = getApp();
        app.globalData.curType = index;
        clearTimeout(this.timer)
    },
    methods:{
        async getadTime() {
            let res = await getByKeyApi("adTime");
            this.adTime = res.data[0]?.configValue;
        },
        getMyInfo() {
            getMyInfoApi().then((res) => {
                this.myInfoVo = res.data;
            });
        },
        getInfo(){
            this.isLoading=true
            getListInfoApi(this.queryData).then(res=>{
                this.isLoading=false
                this.infoData=res.data.vo
                this.userData=res.data.user
                if (res.data.vo.photoUrl){
                    this.swiperList=res.data.vo.photoUrl.split(',')
                }
            })
        },
        handleToTel(){
            watchAdvertisementsApi({city:this.city}).then(res=>{
                this.videoUrl = res.data.urlLink
                this.showVideo=true
                this.$forceUpdate()
                if (res.code==200){
                    //this.adTime后关闭
                    let number = (Number(this.adTime)+1)*1000
                    this.timer = setTimeout(()=>{
                        this.showVideo=false
                        this.videoUrl=''
                        uni.makePhoneCall({
                            phoneNumber: this.infoData.lxrDh
                        })
                    }, number)
                }
            })

        },
        handleShowImg(index){
            // uni.previewImage({
            //     current: 0,
            //     urls: imgList
            // });


            //如果当前点击的是图片
            let isImg = !this.swiperList[index].includes('mp4')
            if (isImg) {
                let priveList=[]
                //取轮播图数组里面的图片 然后预览
                for (let i = 0; i < this.swiperList.length; i++) {
                    if (!this.swiperList[i].includes('mp4')){
                        //图片
                        priveList.push(this.swiperList[i])
                    }
                }
                //预览图片
                uni.previewImage({
                    current:index,
                    urls:priveList
                })
            }
        },
        handleLike(){
            if (this.infoData.sfxh){
                delCollectApi({inFormationId:this.infoData.id}).then(res=>{
                    uni.showToast({
                        title: res.msg,
                        icon: "none",
                        duration: 2000
                    });
                    if(res.code==200){
                        this.getInfo()
                    }
                })
            }else{
                addCollectApi({userIdPassivity:this.infoData.id}).then(res=>{
                    uni.showToast({
                        title: res.msg,
                        icon: "none",
                        duration: 2000
                    });
                    if(res.code==200){
                        this.getInfo()
                    }
                })
            }
        }
    }
}
</script>

<style scoped lang="scss">

</style>
